package apk.yoursms.ad;

import com.StarsSDK.*;
import com.StarsSDK.Beans.ADResponse;

import android.content.SharedPreferences;
import android.util.Log;

public class ShowPopUpAndAd {

    private int showRatingCount = 4;
    private int showAdCount = 4;
    private SharedPreferences prefs;

    public ShowPopUpAndAd(SharedPreferences prefs) {
	this.prefs = prefs;
    }

    public boolean needShowRating() {
	int count = prefs.getInt("rating_count", 0);

	if (count > showRatingCount) {
	    prefs.edit().putInt("rating_count", 0).commit();
	    return true;
	} else {
	    incCount(count, "rating_count");
	    return false;
	}
    }

    public boolean needShowAd() {
	int count = prefs.getInt("ad_count", 0);
	int show = 0;
	StarsSDK.ad;
	try {
	    if (ad.getShowCount() != 0) {
		show = ad.getShowCount();		
	    } else {
		show = showAdCount;
	    }
	} catch (Exception e) {
	    show = showAdCount;
	}
	
	Log.d("ADCOUNT", "" + ad.getShowCount());

	if (count > show) {
	    return true;
	} else {
	    incCount(count, "ad_count");
	    return false;
	}
    }

    private void incCount(int count, String prefKey) {
	count++;
	prefs.edit().putInt(prefKey, count).commit();
    }

}
